/**
 * Sumpu Inc.
 * Copyright (c) 2011-2012 All Rights Reserved. 
 */
package cn.sumpu.app.guoguojie.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.sumpu.app.guoguojie.dao.TopDao;
import cn.sumpu.app.guoguojie.domain.TaobaokeReport;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

/**
 * @author nick
 * @version $Id: TopDaoImpl.java, v 0.1 2012-8-20 下午03:20:25 nick Exp $
 */
public class TopDaoImpl extends SqlSessionDaoSupport implements TopDao {

    private final static Logger logger = LoggerFactory.getLogger(TopDaoImpl.class);

    /**
     * @param taobaokeReport
     * @throws AppBusinessException
     * @see cn.sumpu.app.guoguojie.dao.TopDao#insertTaobaokeReport(cn.sumpu.app.guoguojie.domain.TaobaokeReport)
     */
    @Override
    public void insertTaobaokeReport(TaobaokeReport taobaokeReport) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.TopMapper.insertTaobaokeReport", taobaokeReport);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Insert taobaokeReport database failure.", e);
            }
            throw new AppBusinessException("Insert taobaokeReport database failure.", e);
        }
    }

    //插入淘宝客报表（批量）
    @Override
    public void insertTaobaokeReports(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.TopMapper.insertTaobaokeReports", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Insert insertTaobaokeReports database failure.", e);
            }
            throw new AppBusinessException("Insert insertTaobaokeReports database failure.", e);
        }
    }

    @Override
    public int countTaobaokeReportList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.TopMapper.countTaobaokeReportList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Query database failure.", e);
            }
            throw new AppBusinessException("Query database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<TaobaokeReport> getTaobaokeReportList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<TaobaokeReport>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.TopMapper.getTaobaokeReportList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Query database failure.", e);
            }
            throw new AppBusinessException("Query database failure.", e);
        }
    }

    /**
     * @param taobaokeReport
     * @throws AppBusinessException
     * @see cn.sumpu.app.guoguojie.dao.TopDao#updateTaobaokeReport(cn.sumpu.app.guoguojie.domain.TaobaokeReport)
     */
    @Override
    public void updateTaobaokeReport(TaobaokeReport taobaokeReport) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.TopMapper.updateTaobaokeReport", taobaokeReport);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("updateTaobaokeReport database failure.", e);
            }
            throw new AppBusinessException("updateTaobaokeReport database failure.", e);
        }
    }

}
